﻿//Mr Inventory by David Mauler 10.2.2010
//Mr Inventory is released under the 
//GNU General Public License version 2 (GPLv2)

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Collections;

public partial class showserv : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void onClick_bSearch(object sender, EventArgs e)
    {
        ArrayList servList = new ArrayList();
        ServerSql sqlFind = new ServerSql();
        servList = sqlFind.findByName(tbSerName.Text);

        ddServFnd.Items.Clear();

        if (servList == null)
        {
            lbMessage.Text = "<p class='evenLine'>No servers were found with that name</p>";
        }
        else
        {
            foreach (string server in servList)
            {
                ddServFnd.Items.Add(server);
            }
        }

        bGetServ.Visible = true;
    }

    public void onClick_bGetServ(object sender, EventArgs e)
    {
        ServerSql sqlGetServ = new ServerSql();
        ServerInv serv = sqlGetServ.getByName(ddServFnd.SelectedValue.ToString());

        if (serv == null)
        {
            lbMessage.Text = "<p class='evenLine'>Error returning server</p>";
        }

        if (serv != null)
        {
            lbMessage.Text = @"<p class='evenLine'>Server Name: " + serv.Name + "</p>" +
                              "<p class='oddLine'>OS: " + serv.Os + "</p>" +
                              "<p class='evenLine'>Software: " + serv.Software + "</p>" +
                              "<p class='oddLine'>VM: " + serv.Vm + "</p>" +
                              "<p class='evenLine'>IP: " + serv.Ip + "</p>" +
                              "<p class='oddLine'>Model: " + serv.Model + "</p>" +
                              "<p class='evenLine'>Serial: " + serv.Serial + "</p>" +
                              "<p class='oddLine'>CPU: " + serv.Cpu + "</p>" +
                              "<p class='evenLine'>MEM: " + serv.Mem + "</p>" +
                              "<p class='oddLine'>Storage: " + serv.Storage + "</p>" +
                              "<p class='evenLine'>Location: " + serv.Location + "</p>";
        }
    }

    public void onClick_bDispAll(object sender, EventArgs e)
    {
        string dispServers = @"   <table id='infoTable' class='table' cellspacing='0'>
                                     <tr>
                                        <th>Server</th>
                                        <th>OS</th>
                                        <th>Software</th>
                                        <th>VM</th>
                                        <th>IP</th>
                                        <th>Model</th>
                                        <th>Serial</th>
                                        <th>CPU</th>
                                        <th>Mem</th>
                                        <th>Storage</th>
                                        <th>Location</th>
                                     </tr>";
        bool flip = true;

        ServerSql sqlGetAll = new ServerSql();
        ArrayList servList = new ArrayList();
        servList = sqlGetAll.getAllServ();

        if (servList == null)
        {
            lbMessage.Text = "<p class='evenLine'>Error displaying servers</p>";
        }

        foreach (ServerInv server in servList)
        {
            lbMessage.Text = server.Name;
            if (flip == true)
            {
                dispServers += @"<tr class='evenLineS'><td class=''>" + server.Name + "</td>" +
                                "<td>" + server.Os + "</td>" +
                                "<td>" + server.Software + "</td>" +
                                "<td >" + server.Vm + "</td>" +
                                "<td>" + server.Ip + "</td>" +
                                "<td>" + server.Model + "</td>" +
                                "<td>" + server.Serial + "</td>" +
                                "<td>" + server.Cpu + "</td>" +
                                "<td>" + server.Mem + "</td>" +
                                "<td>" + server.Storage + "</td>" +
                                "<td>" + server.Location + "</td></tr>";
            }

            if (flip == false)
            {
                dispServers += @"<tr class='oddLineS'><td>" + server.Name + "</td>" +
                                "<td>" + server.Os + "</td>" +
                                "<td>" + server.Software + "</td>" +
                                "<td >" + server.Vm + "</td>" +
                                "<td>" + server.Ip + "</td>" +
                                "<td>" + server.Model + "</td>" +
                                "<td>" + server.Serial + "</td>" +
                                "<td>" + server.Cpu + "</td>" +
                                "<td>" + server.Mem + "</td>" +
                                "<td>" + server.Storage + "</td>" +
                                "<td>" + server.Location + "</td></tr>";
            }

            if (flip == true)
            {
                flip = false;
            }
            else
            {
                flip = true;
            }
        }

        dispServers += @"   
                         </table>";

        lbMessage.Text = dispServers;
    }

}

